package com.ruoyi.report.task;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.report.domain.ReportUser;
import com.ruoyi.report.service.IReportUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 定时任务生成报表
 * 
 * @author ruoyi
 */
@Component("reportTask")
public class reportTask
{
    @Autowired
    private IReportUserService reportUserService;

    public void ryNoParams()
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.MONTH, -1);
        String reportMonth = new SimpleDateFormat("yyyy-MM").format(calendar.getTime());

        ReportUser reportUser = new ReportUser();
        List<ReportUser> list = reportUserService.selectUserReportList(reportUser);
        for(ReportUser user : list) {
            user.setReportMonth(reportMonth);
            user.setCreateTime(DateUtils.getNowDate());
        }
        reportUserService.saveBatch(list);
    }
}
